import pojo.Student;
import pojo.StudentComparator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.BiFunction;

public class MethodReference {

    public static void main(String[] args) {
        List<Student> studentList = generateStudentData();
        System.out.println(studentList);

        //Lambda方式
//        studentList.sort((stu1,stu2)->Student.compareStudentByScore(stu1,stu2));
        //第一种引用方式=》静态方法引用
//        studentList.sort(Student::compareStudentByScore);
        //第二中引用方式=》对象方法引用
//        studentList.sort(Student::compareScore);

        //第三种引用方式=》实例方法引用
//        StudentComparator stuComparator = new StudentComparator();
//        studentList.sort(stuComparator::compareStudentByScore);


//        第四种引用方式=》构造方法引用
//        Lambda方式
        Student student1 = iniStudent("lishid", 50, (a1 ,a2) -> new Student(a1 ,a2));
        //方法引用方式
        Student student2 = iniStudent("lishid", 50, Student::new);
        System.out.println(1);


        ///迭代器遍历
        Iterator<Student> iterator = studentList.iterator();
        while (iterator.hasNext()){
            Student student = iterator.next();
            if(student.getScore() == 79){
                iterator.remove();
            }
        }

        System.out.println(1111);

    }

    //生成模拟数据
    public static List<Student> generateStudentData(){
        List<Student> list = new ArrayList<>();
        list.add(new Student("zhangsna",90));
        list.add(new Student("wang",50));
        list.add(new Student("zhaosl",79));
        return list;
    }

    public static Student iniStudent(String name, Integer score, BiFunction<String,Integer,Student> function){
        return function.apply(name, score);
    }
}
